
package GUILayer;

import java.awt.Color;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;
import javax.swing.JTextField;

import CTRLayer.ActivityDetailsCTR;
import CTRLayer.PersonCTR;
import CTRLayer.TrainedCTR;
import ModelLayer.Person;
import ModelLayer.Trained;

public class ActivityDetails
{
	private PersonCTR pc;
	private TrainedCTR tc;
	private JTextField textField;
	private JTextField textField_1;
	private Person child;
	private Trained t;
	private JTextPane textPane;
	private JTextPane textPane_1;
	private JTextPane textPane_2;
	private ModelLayer.ActivityDetails ad;
	private ActivityDetailsCTR adc;
	
	public ActivityDetails()
	{
		adc = new ActivityDetailsCTR();
		pc = new PersonCTR();
		tc = new TrainedCTR();
		JFrame logbook = new JFrame();
		logbook.setTitle("ParaManagement - Aktivitetesdetaljer");
		logbook.setBounds(100, 100, 600, 600);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		JLabel lblAktivitet = new JLabel("Aktivitet:");
		
		JLabel lblBarn = new JLabel("Barn:");
		
		textField = new JTextField();
		textField.setBorder(null);
		textField.setEditable(false);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBorder(null);
		textField_1.setEditable(false);
		textField_1.setColumns(10);
		
		GroupLayout gl_panel_2 = new GroupLayout(panel_2);
		gl_panel_2.setHorizontalGroup(
			gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_2.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_2.createSequentialGroup()
							.addComponent(lblAktivitet)
							.addPreferredGap(ComponentPlacement.RELATED, 1, Short.MAX_VALUE)
							.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel_2.createSequentialGroup()
							.addComponent(lblBarn)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap())
		);
		gl_panel_2.setVerticalGroup(
			gl_panel_2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_2.createSequentialGroup()
					.addGap(5)
					.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblAktivitet)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblBarn)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panel_2.setLayout(gl_panel_2);
		
		JPanel panel = new JPanel();
		
		JPanel panel_1 = new JPanel();
		
		JLabel lblForudstninger = new JLabel("Foruds\u00E6tninger");
		
		textPane_1 = new JTextPane();
		textPane_1.setEditable(false);
		textPane_1.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGap(0, 564, Short.MAX_VALUE)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addComponent(textPane_1, GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
						.addComponent(lblForudstninger))
					.addContainerGap())
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGap(0, 97, Short.MAX_VALUE)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblForudstninger)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textPane_1, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
		);
		panel_1.setLayout(gl_panel_1);
		
		JPanel panel_3 = new JPanel();
		
		JLabel lblTrainingProcedure = new JLabel("Tr\u00E6ningsprocedure");
		
		textPane_2 = new JTextPane();
		textPane_2.setEditable(false);
		textPane_2.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		GroupLayout gl_panel_3 = new GroupLayout(panel_3);
		gl_panel_3.setHorizontalGroup(
			gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGap(0, 564, Short.MAX_VALUE)
				.addGroup(gl_panel_3.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_3.createParallelGroup(Alignment.LEADING)
						.addComponent(textPane_2, GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
						.addComponent(lblTrainingProcedure))
					.addContainerGap())
		);
		gl_panel_3.setVerticalGroup(
			gl_panel_3.createParallelGroup(Alignment.LEADING)
				.addGap(0, 97, Short.MAX_VALUE)
				.addGroup(gl_panel_3.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblTrainingProcedure)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textPane_2, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
		);
		panel_3.setLayout(gl_panel_3);
		GroupLayout groupLayout = new GroupLayout(logbook.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(panel, GroupLayout.DEFAULT_SIZE, 564, Short.MAX_VALUE)
								.addComponent(panel_3, GroupLayout.PREFERRED_SIZE, 564, GroupLayout.PREFERRED_SIZE)
								.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 564, GroupLayout.PREFERRED_SIZE))
							.addContainerGap())
						.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
							.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 205, GroupLayout.PREFERRED_SIZE)
							.addGap(177))))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
					.addGap(18)
					.addComponent(panel_3, GroupLayout.PREFERRED_SIZE, 179, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		
		JLabel lblGoal = new JLabel("M\u00E5l");
		
		textPane = new JTextPane();
		textPane.getText();
		textPane.setEditable(false);
		textPane.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(textPane, GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
						.addComponent(lblGoal))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblGoal)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textPane, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		logbook.getContentPane().setLayout(groupLayout);
		logbook.setVisible(true);
	
		getChild();
		getTrained();
		getActivityDetails();
	}
	
	public void getChild()
	{
		String phonenr = "98211345";
		child = pc.findPersonPhoneNr(phonenr);
		
		if(child == null)
        {
        	textField.setText("Barnet eksisterer ikke.");
        }
        else
        {
        	textField.setText(child.getfName() + " " + child.getlName());
        }
    }
	
	public void getTrained()
	{
		int trainedID = 1;
		t = tc.findTrainedID(trainedID);
		
		if(t == null)
        {
        	textField_1.setText("Aktivitet eksisterer ikke.");
        }
        else
        {
        	textField_1.setText(t.getName());
        }
	}
	
	public void getActivityDetails()
	{
		int id = 1;
		ad = adc.findActivityDetailsID(id);
		if(ad == null)
		{
			System.out.println("Der er ingen aktivitetsdetaljer!");
		}
		else
		{
			textPane.setText(ad.getGoal());
        	textPane_1.setText(ad.getRequirements());
        	textPane_2.setText(ad.getTrainingProcedure());
		}
	}
}
